cmake_minimum_required(VERSION 2.6)

project(proxyproto-server)

# 生成构建时间
string(TIMESTAMP BUILD_TIMESTAMP %Y%m%d_%H%M%S)

# 设置构建版本
set(VERSION_MAJOR 1)
set(VERSION_MINOR 1)
set(VERSION_PATCH 0)

configure_file(
    "${CMAKE_SOURCE_DIR}/src/build_info.h.in"
    "${CMAKE_SOURCE_DIR}/src/build_info.h"
)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -s")

# 检查c++编译器标志，设置c++11支持变量
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)

# 使用变量设置编译标志
if(COMPILER_SUPPORTS_CXX11)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif(COMPILER_SUPPORTS_CXX0X)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else()
    message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()

include_directories(${CMAKE_SOURCE_DIR}/src)

set(proxyproto_server_sources
    src/main.cc
    src/conf.cc
    src/logging.cc
    src/server.cc
    src/util.cc
    src/proxyproto.cc
    src/inet_address.cc)

add_executable(proxyproto-server ${proxyproto_server_sources})
target_link_libraries(proxyproto-server -static-libgcc -static-libstdc++)
